<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$city=$this->model('city')->gocity($_RQ);
	$return['pcd']=$city['pcd'];
	$return['city']=$city;
	$cid=intval($_RQ['cid']);
	$return['welcomehdps']=$return['pluginset']['welcomehdps'];
	if(count($return['welcomehdps'])>0 && $return['pluginset']['iswelcome']==1){
		$return['iswelcome']=$this->session('iswelcome')?0:1;
		if($return['iswelcome']){
			$this->session('iswelcome',1);
		}
	}
	$return['pluginset']['searchkeyword']=$return['pluginset']['searchkeyword']?explode('|',$return['pluginset']['searchkeyword']):array('奶茶','一点点','炸鸡','麦当劳','奈雪','鸭脖');
	$return['member']=cfc('core')->get_member($_SESSION['uid']);
	$pindex = max(1, intval($post['page']));
	$psize = 10;
	$total='';
	$shopset=plugin('jy_weishop')->plugin_setting('setting');
	$sale_luck=plugin('jy_weishop')->plugin_setting('sale_luck');
	if($sale_luck['isopen']==1){
			if(isset($_RQ['luckkey'])){
				$return['sale_luck']=model('jy_weishop/activity/sales')->jieluck($_RQ['luckkey']);
			}else{
				$return['sale_luck']=model('jy_weishop/activity/sales')->getluck();
			}
	}
	if(!$return['sale_luck']){
			$isshow_sale_offer=$this->session('isshow_sale_offer');
			if(!$isshow_sale_offer){
				$return['sale_offer']=model('jy_weishop/activity/sales')->getoffer();
			}
			if(!$return['sale_offer']){
				if($shopset['no_ordermodal']!=1){
					$return['orderlist']=pdo_getslice('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'deleted'=>0,'status'=>0),array($pindex,$psize),$total,'','','createtime desc');
					foreach($return['orderlist'] as &$ov){
						$ordergoods=pdo_get('jy_weishop_order_goods',array('orderid'=>$ov['id'],'uniacid'=>$_SESSION['uniacid']),array('goodsid','optionid','price','total','goodssn','productsn'));
						$goodsinfo=pdo_get('jy_weishop_goods',array('id'=>$ordergoods['goodsid'],'uniacid'=>$_SESSION['uniacid']),array('id','image','title','merchid'));
						$ov['goods']=array_merge($ordergoods,$goodsinfo);
						$ov['createtime']=date('Y/m/d H:i:s',$ov['createtime']);
						$ov['total']=pdo_getsum('jy_weishop_order_goods',array('orderid'=>$ov['id'],'uniacid'=>$_SESSION['uniacid']),'total');
					}
					$return['allprice']=pdo_getsum('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'deleted'=>0,'status'=>0),'price');
				}
				if(empty($return['orderlist'])){
					$return['coupon_wait']=model('jy_weishop/task')->pop_coupon_wait();
					$return['coupon_wait']=$return['coupon_wait']?$return['coupon_wait'][0]:false;
					if(!$return['coupon_wait']){
						$return['coupon_hd']=model('jy_weishop/task')->pop_coupon_hd();
						if(!$return['coupon_hd']){
							$return['game_wait']=model('jy_weishop/task')->pop_game();
						}
					}
				}
			}else{
					$this->session('isshow_sale_offer',1);
			}
	}
	$sharelink='jy_newpaimerch/mymerchlist//cityid='.$_SESSION['cityid'].'&fromuser='.$_SESSION['uid'];
	$return['sharedata']=array(
			'title'=>'收藏商家',
			'desc'=>'收藏商家，一个属于自己的商家联盟！',
			'link'=>custom_url($sharelink,true),
			'imgUrl'=>ATTACHMENT_URL.$setting['share_image']
	);
	//获取当前时间：
	$showtypetime1=mktime(10,30,0,date('m'),date('d'),date('Y'));
	$showtypetime2=mktime(14,00,0,date('m'),date('d'),date('Y'));
	$showtypetime3=mktime(17,00,0,date('m'),date('d'),date('Y'));
	$showtypetime4=mktime(21,00,0,date('m'),date('d'),date('Y'));
	if(TIMESTAMP<$showtypetime1){
		$return['showtype']=1;
	}elseif(TIMESTAMP>$showtypetime1 && TIMESTAMP<$showtypetime2){
		$return['showtype']=2;
	}elseif(TIMESTAMP>$showtypetime2 && TIMESTAMP<$showtypetime3){
		$return['showtype']=3;
	}elseif(TIMESTAMP>$showtypetime3 && TIMESTAMP<$showtypetime4){
		$return['showtype']=4;
	}elseif(TIMESTAMP>$showtypetime4){
		$return['showtype']=5;
	}
	$return['list']=array();
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($cid){
		$params['id']=$cid;
	}
	$return['merchgroups']=pdo_getall('jy_merch_category',$params);
	$return['coupons']=model('jy_weishop/coupon')->getmerchcoupon(0,1);
	$return['params']=array('islike'=>1,'page'=>1,'cid'=>$cid,'pid'=>'all');
	set_html('title','我的收藏');
	exi($return);
}
?>